package info.xiao.dataStructrue.queue;

import java.util.Stack;

/**
 * @Classname CQueue 两个栈实现一个队列
 * @Description 链接： https://leetcode.cn/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof/
 * @Date 2022/10/25 14:35
 * @Created by 晓龙Oba
 */
public class CQueue {

    private Stack<Integer> stackA;

    private Stack<Integer> stackB;

    public CQueue() {
        stackA = new Stack<>();
        stackB = new Stack<>();
    }

    public void appendTail(int value) {
        while (!stackB.isEmpty()) {
            stackA.push(stackB.pop());
        }
        stackA.push(value);
    }

    public int deleteHead() {
        while (!stackA.isEmpty()) {
            stackB.push(stackA.pop());
        }
        return stackB.isEmpty() ? -1 : stackB.pop();
    }
}
